import java.io.IOException;

import javax.swing.JOptionPane;

import adapterHandler.GuiSockAdapter;

import socketHandler.MySocket;
import socketHandler.SocketReader;
import guiHandler.myFrame;
/**
 * 
 * @author Peter Steiner & Fredrik Wallenius
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(final String[] args) {
		
		MySocket mySocket = null;
		GuiSockAdapter adapter = null;
		final myFrame frame;
		try {
			adapter = new GuiSockAdapter();
			mySocket = new MySocket(args);
			frame = new myFrame(adapter);
			
			adapter.setData(mySocket.getData());
			adapter.setChatWindow(frame.getChatWindow());
			adapter.setSocket(mySocket);
			
			String newName = (String)JOptionPane.showInputDialog(
	                null,
	                "Please enter the name you wish to use:",
	                "OPS Chat client",
	                JOptionPane.PLAIN_MESSAGE);
			
			mySocket.getData().setUserName(newName);
			
			mySocket.serverHandshake();
			SocketReader socketReader = new SocketReader(adapter);
			socketReader.startActivity();
			
			//System.out.println("[Client]: chat should be running...");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
